package com.itheima.d5_resource;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/*
     目标：掌握释放资源的方式。
 */
public class Test2 {
    public static void main(String[] args) {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream("E:\\ttt\\a.txt");
            fos = new FileOutputStream("E:\\ttt\\ws.txt");
            int l;
            byte[] bb = new byte[1024];
            while ((l = fis.read(bb)) != -1) {
                System.out.println(l);
                fos.write(bb, 0, l);
            }
        } catch (Exception e) {

        } finally {
            if (fos != null) {

                try {
                    fos.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if (fos != null) {

                try {
                    fis.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

        }
    }
}
